<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Achievements
 *
 * @property int $id
 * @property int $uid
 * @property float $amount
 * @property string $datestamp
 * @property int $created_at
 * @property int $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Achievements whereAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Achievements whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Achievements whereDatestamp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Achievements whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Achievements whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Achievements whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property-read \App\Models\User $user
 * @property float $achievement 个人业绩
 * @property float|null $node_achievement 节点业绩
 * @property float $commission 个人佣金
 * @property float $node_commission 节点佣金
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Achievements whereAchievement($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Achievements whereCommission($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Achievements whereNodeAchievement($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Achievements whereNodeCommission($value)
 */
class Achievements extends Model
{
    protected $table = 'achievements';
    protected $primaryKey = 'id';
    protected $guarded = [];

    public $timestamps = false;

    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::creating(function ($model){
            if (!$model->created_at) $model->created_at = time();
        });

        static::updating(function ($model){
            if (!$model->updated_at) $model->updated_at = time();
        });
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'uid');
    }
}
